﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Movie : System.Web.UI.Page
{
    #region
    Product pd = new Product();
    static PagedDataSource p = new PagedDataSource();
    public static int intSTT;
    public static int page = 0;
    public static string ld=null;
    #endregion
    public void loaddata(DateTime date)
    {
        try
        {
            p.DataSource = pd.GetMovie(date);
            p.PageSize = 6;
            p.CurrentPageIndex = page;
            p.AllowPaging = true;
            lbtnFirst.Enabled = true; lbtnPrevious.Enabled = true; lbtnNext.Enabled = true; lbtnLast.Enabled = true;
            if (p.IsFirstPage == true)
            {
                lbtnFirst.Enabled = false;
                lbtnPrevious.Enabled = false;
                lbtnNext.Enabled = true;
                lbtnLast.Enabled = true;
            }
            if (p.IsLastPage == true)
            {
                lbtnFirst.Enabled = true;
                lbtnPrevious.Enabled = true;
                lbtnNext.Enabled = false;
                lbtnLast.Enabled = false;
            }
            txtShow.Text = (page + 1) + " / " + p.PageCount;
            dtlShow.DataSource = p;
            dtlShow.DataBind();
        }
        catch (Exception)
        {
        }
    }
    public void loaddataY(DateTime date)
    {
        try
        {
            p.DataSource = pd.GetMovieY(date);
            p.PageSize = 6;
            p.CurrentPageIndex = page;
            p.AllowPaging = true;
            lbtnFirst.Enabled = true; lbtnPrevious.Enabled = true; lbtnNext.Enabled = true; lbtnLast.Enabled = true;
            if (p.IsFirstPage == true)
            {
                lbtnFirst.Enabled = false;
                lbtnPrevious.Enabled = false;
                lbtnNext.Enabled = true;
                lbtnLast.Enabled = true;
            }
            if (p.IsLastPage == true)
            {
                lbtnFirst.Enabled = true;
                lbtnPrevious.Enabled = true;
                lbtnNext.Enabled = false;
                lbtnLast.Enabled = false;
            }
            txtShow.Text = (page + 1) + " / " + p.PageCount;
            dtlShow.DataSource = p;
            dtlShow.DataBind();
        }
        catch (Exception)
        {
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            page = 0;
            DateTime day = DateTime.Now.Date;
            loaddata(day);
            lblTitle1.Text = "Movie Released";
            lbtnReleased.ForeColor = System.Drawing.Color.Red;
            ddlMoviName.DataSource = pd.GetMovie(day);
            ddlMoviName.DataTextField = "MovieName";
            ddlMoviName.DataValueField = "MovieID";
            ddlMoviName.DataBind();
        }
    }
    protected void lbtnFirst_Click(object sender, EventArgs e)
    {
        page = 0;
        if ("R".Equals(ld))
        {
            DateTime day = DateTime.Now.Date;
            loaddata(day);
        }
        else
        {
            DateTime day = DateTime.Now.Date;
            loaddataY(day);
        }
    }
    protected void lbtnPrevious_Click(object sender, EventArgs e)
    {
        page = page-1;
        if ("R".Equals(ld))
        {
            DateTime day = DateTime.Now.Date;
            loaddata(day);
        }
        else
        {
            DateTime day = DateTime.Now.Date;
            loaddataY(day);
        }
    }
    protected void lbtnNext_Click(object sender, EventArgs e)
    {
        page = page+1;
        if ("R".Equals(ld))
        {
            DateTime day = DateTime.Now.Date;
            loaddata(day);
        }
        else
        {
            DateTime day = DateTime.Now.Date;
            loaddataY(day);
        }
    }
    protected void lbtnLast_Click(object sender, EventArgs e)
    {
        page = p.PageCount - 1;
        if ("R".Equals(ld))
        {
            DateTime day = DateTime.Now.Date;
            loaddata(day);
        }
        else
        {
            DateTime day = DateTime.Now.Date;
            loaddataY(day);
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender;
        string id = btn.CommandArgument.ToString();
        Session["MovieID"] = id;
        Response.Redirect("ViewMovies.aspx");
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        string id = btn.CommandArgument.ToString();
        Session["MovieID"] = id;
        Response.Redirect("ViewMovies.aspx");
    }
    protected void lbtnReleasedYet_Click1(object sender, EventArgs e)
    {
        page = 0;
        ld = "RY";
        DateTime day = DateTime.Now.Date;
        loaddataY(day);
        lblTitle1.Text = "Movie Released Yet";
        lbtnReleased.ForeColor = System.Drawing.Color.SkyBlue;
        lbtnReleasedYet.ForeColor = System.Drawing.Color.Red;
    }
    protected void lbtnReleased_Click1(object sender, EventArgs e)
    {
        page = 0;
        ld = "R";
        DateTime day = DateTime.Now.Date;
        loaddata(day);
        lblTitle1.Text = "Movie Released";
        lbtnReleased.ForeColor = System.Drawing.Color.Red;
        lbtnReleasedYet.ForeColor = System.Drawing.Color.SkyBlue;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (null != txtDate.Text.Trim())
        {
            dtlShow.DataSource = pd.GetMovie(DateTime.Parse(txtDate.Text.Trim()));
            dtlShow.DataBind();
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = "Please select a date!!!";
        }
        
    }
    protected void ddlMoviName_SelectedIndexChanged(object sender, EventArgs e)
    {
        dtlShow.DataSource = pd.GetMovieById(ddlMoviName.Text.Trim());
        dtlShow.DataBind();
    }
    protected void lbtnBookingTicket_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender;
        string id = btn.CommandArgument.ToString();
        Session["MovieID"] = id;
    }
}